﻿using System;
using System.Collections.Generic;
using System.Data;
using Module.Common.Models;
using Module.Core.DAO;
using Module.Core.EntitiesInfo;


namespace Module.Core.BusinessLogic
{
    public class ProductOrderBL
	{
		/// <summary>
		/// Saves a record to the ProductOrder table.
		/// </summary>
		public static int Insert(ProductOrderInfo productOrderInfo)
		{
			try
			{
				return new ProductOrderDAO().Insert(productOrderInfo);
			}
			catch (Exception ex)
			{
				throw;
			}

		}        

		/// <summary>
		/// Saves a record to the ProductOrder table.
		/// </summary>
        public static void Update(ProductOrderInfo productOrderInfo)
		{
			try
			{
				new ProductOrderDAO().Update(productOrderInfo);
			}
			catch (Exception ex)
			{
				throw;
			}

		}

		/// <summary>
		/// Delete a record from the ProductOrder table.
		/// </summary>
        public static void Delete(string orderId,int param)
		{
			try
			{
				new ProductOrderDAO().Delete(orderId,param);
			}
			catch (Exception ex)
			{
				throw;
			}

		}

		/// <summary>
		/// Selects a single record from the ProductOrder table.
		/// </summary>
        public static ProductOrderInfo Select(string codeMember)
		{
			try
			{
                return new ProductOrderDAO().Select(codeMember);
			}
			catch (Exception ex)
			{
				throw;
			}

		}

        /// <summary>
        /// Selects a single record from the ProductOrder table.
        /// </summary>
        public static ProductOrderInfo Selects(int type,string param)
        {
            try
            {
                return new ProductOrderDAO().Selects(type,param);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

		/// <summary>
		/// Selects all records from the ProductOrder table.
		/// </summary>
        public static CHRTList<ProductOrderInfo> SelectAll()
		{
			try
			{
				return new ProductOrderDAO().SelectAll();
			}
			catch (Exception ex)
			{
				throw;
			}

		}

        /// <summary>
        /// Lấy tổng số bản ghi
        /// </summary>        
        /// <param name="isTotalRow">=True lấy tổng sổ bản ghi</param>
        /// <returns></returns>
        public static int SelectCount(int status, int codeMember, string starDatetime, string endDatetime)
        {
            try
            {
                return new ProductOrderDAO().SelectCount(status, codeMember, starDatetime, endDatetime);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        public static DataTable Search(int status, int codeMember, string starDatetime, string endDatetime, int beginRow, int endRow, string orderByColumn)
        {
            try
            {
                return new ProductOrderDAO().Search(status, codeMember, starDatetime, endDatetime, beginRow, endRow, orderByColumn);
            }
            catch (Exception ex)
            {
                throw;
            }

        }


        public static int SumDealxu(int type, string param)
        {
            try
            {
                return new ProductOrderDAO().SumDealxu(type, param);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        //Update lại trạng thái Status=2 -Đơn hàng đang chờ xác nhận
        //Status=1 -Đơn hàng đã xác nhận
        public static void UpdateStatus(int orderId, int status)
        {
            try
            {
                new ProductOrderDAO().UpdateStatus(orderId, status);
            }
            catch (Exception ex)
            {
                throw;
            }

        }


        //Bind du lieu vao droplist
        public static DataSet BindDropdownlist(int orderId)
        {
            try
            {
                DataSet ds = new DataSet();

                ds = new ProductOrderDAO().BindDropdownlist(orderId);
                if (ds != null)
                    return ds;
                return null;
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        //Danh sách đơn hàng hiện thị ngoài website

        public static DataSet ListProductOrder(string codeMember, string email, int currPage, int recodperPage, int pageSize,string link)
        {
            try
            {
                DataSet ds = new DataSet();

                ds = new ProductOrderDAO().ListProductOrder(codeMember, email, currPage, recodperPage, pageSize,link);
                if (ds != null)
                    return ds;
                return null;
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static void Member_UpdateGoldMuaHang(int type, string codeMember_from, float totalPrice)
        {
            try
            {
                new ProductOrderDAO().Member_UpdateGoldMuaHang(type, codeMember_from, totalPrice);
            }
            catch (Exception)
            {

                throw;
            }
        }

	}
}
